package com.portal.framework.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class TypeFormat {

	private static SimpleDateFormat sDateFormat=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	/**
	 * ��ȡDouble����
	 * @param obj
	 * @return
	 */
	public static Double dataFormatToDouble(Object obj) throws ParseException{
		
		if(null!=obj){
			return Double.parseDouble(obj.toString());
		}
		return 0.0;
	}
	
	/**
	 * ���ַ�ת����ʱ������
	 * @return
	 * @throws ParseException
	 */
	public static Date dataFormatToDate(Object obj) throws ParseException{
		
		if(null!=obj){
			return sDateFormat.parse(obj.toString());
		}
		return null;
	}
	
	public static String dataToString(Object obj){
		if(null!=obj){
			return obj.toString();
		}
		else{ 
			return "";
		}
		
	}
	
	/**
	 * ��ȡ��ǰ�����ַ�
	 * @return
	 * @throws ParseException
	 */
	public static String getDate(String format) throws ParseException{
		SimpleDateFormat sdf = new SimpleDateFormat(format); 
		return sdf.format(new Date());
	}
	
	
	public static Date dateFormat(Object obj){
		if(null != obj)
			return (Date)obj; 
		else
			return null;
	}
	
	/**
	 * ��ȡInteger����
	 * @param obj
	 * @return
	 */
	public static Integer dataFormatToInteger(Object obj)throws ParseException{
		if(null!=obj){
			return Integer.parseInt(obj.toString());
		}
		return 0;
	}
	
	/**
	 * ��ȡFloat����
	 * @param obj
	 * @return
	 */
	public static Float dataFormatToFloat(Object obj)throws ParseException{
		
		if(null!=obj){
			return Float.parseFloat(obj.toString());
		}
		return 0f;
	}
	
	
	/**
	 * @remark ��֤ĳ������Ƿ�Ϊ��
	 *  TypeFormat	
	 *  boolean 
	 *	@param obj
	 *	@return true:��Ϊ��,false:Ϊ��
	 */
	public static boolean isNotEmptyorNull(Object obj){
		
		if(obj==null || obj.equals("") || obj.equals("null")){
			return false;
		}
		return true;
	}
	
	/**
	 *  ��ʽ����������
	 *  TypeFormat	
	 *  String 
	 *	@param date
	 *	@return
	 */
	public static String dateToString(Date date){
		
		return sDateFormat.format(date);
		
	}
	/**
	 * �ж�string�Ƿ�Ϊ������
	 * Author SOFEI
	 * @param node
	 * @return
	 * @throws Exception
	 */
	  public static boolean isnumber(String value) {
		 try {
			Integer.parseInt(value);
			return true;
		} catch (NumberFormatException e) {
			return false;
		}
	  }
		
}
